
	** Clean Niger Wave 3
	
	** Merge datasets
		
		use "$dir/rawdata/EHCVM Niger/2018/ehcvm_individu_ner2018.dta", clear // roster
			isid hhid numind
			ren numind indiv // renaming individual id to indiv for consistency with other countries
			gen menage_str=string(menage)
			replace menage_str="00"+menage_str if strlen(menage_str)==1
			replace menage_str="0"+menage_str if strlen(menage_str)==2
			gen grappe_str=string(grappe)
			gen test=grappe_str+menage_str
			tostring(hhid), replace
			assert test==hhid
			tempfile roster
			save `roster', replace
			
		use "$dir/rawdata/EHCVM Niger/2018/s04_me_ner2018.dta", clear // employment
			gen menage_str=string(menage)
			replace menage_str="00"+menage_str if strlen(menage_str)==1
			replace menage_str="0"+menage_str if strlen(menage_str)==2
			gen grappe_str=string(grappe)
			gen hhid=grappe_str+menage_str
			gen indiv=s01q00a
			tempfile empl
			save `empl', replace
			
		use "$dir/rawdata/EHCVM Niger/2018/s03_me_ner2018.dta", clear // health
			gen menage_str=string(menage)
			replace menage_str="00"+menage_str if strlen(menage_str)==1
			replace menage_str="0"+menage_str if strlen(menage_str)==2
			gen grappe_str=string(grappe)
			gen hhid=grappe_str+menage_str
			gen indiv=s01q00a
			tempfile health
			save `health', replace
			
			use `roster', clear
			merge 1:1 hhid indiv using `empl', gen(merge_employment) assert(matched)
			merge 1:1 hhid indiv using `health', gen(merge_health) assert(matched)
	
		***********
		***********	
	
		** Household size
			gen w3_inhh=resid==1
			bys hhid: egen w3_hh_size=total(w3_inhh)
			
		** Marital status
			gen w3_married=(mstat==2 | mstat==3) if !missing(mstat)

		** Female
			gen w3_female=(sexe==2) if !missing(sexe)

		** Age
			gen w3_age=age
		
		** Urban status
			gen w3_urban=milieu==1 if !missing(milieu)
			
		***********
		***********
		
		** Any work
		
			** In last 7 days, any work in agriculture
				gen w3_work_agHH=(s04q06==1) if !missing(s04q06)
				replace w3_work_agHH = 1 if s04q13 == 1
				replace w3_work_agHH = 0 if missing(w3_work_agHH) & s04q13!=1 & !missing(s04q13) // doesn't make a difference
				
			** In last 7 days, any work in some kind of trade or salaried employment (for household or otherwise)
				gen w3_work_bizHHother=(s04q07==1) if !missing(s04q07)
				replace w3_work_bizHHother = 1 if s04q14 == 1
				replace w3_work_bizHHother = 0 if missing(w3_work_bizHHother) & s04q14!=1 & !missing(s04q14) // doesn't make a difference
				
			** In last 7 days, any work outside the HH
				gen w3_work_outsideHH=(s04q08==1) if !missing(s04q08)
				 
			** Apprenticeshops: s04q09: Not including
				
			** Any work in last 7 days (agriculture, for non-HH member, own account/business)
				gen w3_worked_last7days=0
				replace w3_worked_last7days=1 if s04q06==1 | s04q13 == 1
				replace w3_worked_last7days=1 if s04q07==1 | s04q14 == 1
				replace w3_worked_last7days=1 if s04q08==1
				replace w3_worked_last7days=. if missing(s04q06) & missing(s04q07) & missing(s04q08)
						
		** Work hours
	
			** Usual months per year
				gen w3_worked_monthsperyear=s04q32
				
					gen w3_worked_monthsperyear_sec=s04q54
		
			** Usual days per month
				gen w3_worked_dayspermonth=s04q36
				*replace w3_worked_dayspermonth=0 if w3_worked_last7days==0 // not enforcing since about work over last 12 months, not last 7 days
					
					gen w3_worked_dayspermonth_sec=s04q55
					
			** Usual hours per day
				gen w3_worked_hoursperday=s04q37
				*replace w3_worked_hoursperday=0 if w3_worked_last7days==0 // not enforcing
				
					gen w3_worked_hoursperday_sec=s04q56
				
			** Weekly hours
				gen w3_work_hrs=((w3_worked_monthsperyear/12) * w3_worked_dayspermonth/((30/7)) * w3_worked_hoursperday) // interpretation is typical weekly hours
				gen w3_work_hrs_sec=((w3_worked_monthsperyear_sec/12) * w3_worked_dayspermonth_sec/((30/7)) * w3_worked_hoursperday_sec)
				
				replace w3_work_hrs=w3_work_hrs+w3_work_hrs_sec if !missing(w3_work_hrs_sec)			
			
		***********
		***********
		
		** Any illness or injury during the last 30 days
			gen w3_illinj=(s03q01==1) if !missing(s03q01)

		** Had to stop usual activity in the past 4 weeks
			gen w3_illinj_stopactivity=(s03q03==1) if !missing(s03q03)
			replace w3_illinj_stopactivity=0 if w3_illinj==0
			
			
		***********
		***********
		
		** Depression
		
			** N/A
			
		***********
		***********
		
		** Functional limitations
		
			* Relevant variables: s03q41 s03q42 s03q43 s03q44 s03q45 s03q46
			
		** Difficulty seeing
			tab1 s03q41, nol
			tab1 s03q41
			gen w3_diff_seei=1 if inlist(s03q41, 2, 3, 4) // 0 if can see without any difficulty
			replace w3_diff_seei=0 if inlist(s03q41, 1)
			replace w3_diff_seei=. if inlist(s03q41, 5) // 5 is not concerned
			tab1 w3_diff_seei

		** Difficulty hearing
			tab1 s03q42, nol
			tab1 s03q42
			gen w3_diff_hear=1 if inlist(s03q42, 2, 3, 4) 
			replace w3_diff_hear=0 if inlist(s03q42, 1)
			replace w3_diff_hear=. if inlist(s03q42, 5)
			tab1 w3_diff_hear

		** Difficulty walking or climbing stairs	
			tab1 s03q43, nol
			tab1 s03q43
			gen w3_diff_walk_clim=1 if inlist(s03q43, 2, 3, 4) 
			replace w3_diff_walk_clim=0 if inlist(s03q43, 1)
			replace w3_diff_walk_clim=. if inlist(s03q43, 5)
			tab1 w3_diff_walk_clim

		** Difficulty remembering or concentrating
			tab1 s03q44, nol
			tab1 s03q44
			gen w3_diff_reme=1 if inlist(s03q44, 2, 3, 4) 
			replace w3_diff_reme=0 if inlist(s03q44,1)
			replace w3_diff_reme=. if inlist(s03q44, 5)
			tab1 w3_diff_reme

		** Difficulty with self-care
			tab1 s03q45, nol
			tab1 s03q45
			gen w3_diff_self_care=1 if inlist(s03q45, 2, 3, 4)
			replace w3_diff_self_care=0 if inlist(s03q45, 1)
			replace w3_diff_self_care=. if inlist(s03q45, 5)
			tab1 w3_diff_self_care

		** Difficulty communicating
			tab1 s03q46, nol
			tab1 s03q46
			gen w3_diff_comm=1 if inlist(s03q46, 2, 3, 4) 
			replace w3_diff_comm=0 if inlist(s03q46, 1)
			replace w3_diff_comm=. if inlist(s03q46, 5)
			tab1 w3_diff_comm
			
				
		***********
		***********
		
		ren grappe w3_grappe 
		
		keep hhid indiv w3*
		order hhid indiv w3*
		save "$dir/data/niger_w3_individual.dta", replace
